package lesson13;

import javax.swing.*;
import java.awt.*;

public class Test01 extends JFrame {
    private Image iconImg = new ImageIcon("images/icon.png").getImage();
    private Image bgImg = new ImageIcon("images/green.jpg").getImage();
    private Font font = new Font("宋体",Font.PLAIN,25);
    public Test01(){

        // 设置背景图
        this.setContentPane(new JPanel(){
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(bgImg,0,0,800,600,this);
            }
        });
        // 设置布局管理器为空
        this.setLayout(null);

        // 按钮组件
        JButton button = new JButton("按钮");
        button.setBounds(0,0,150,50);

        // 标签组件
        JLabel label = new JLabel("用户名：");
        label.setBounds(0, 50,100,50);
        // 修改字体大小
        label.setFont(font);
        // 修改字体颜色
        label.setForeground(Color.RED);
        // 单行文本框组件
        JTextField userTextField = new JTextField();
        userTextField.setBounds(100,50,300,50);
        // 密码框组件
        JPasswordField userPasswordField = new JPasswordField();
        userPasswordField.setBounds(100,100,300,50);
        // 单选框组件
        JRadioButton maleRadio = new JRadioButton("男");
        maleRadio.setBounds(100,150,50,50);
        JRadioButton femaleRadio = new JRadioButton("女");
        femaleRadio.setBounds(150,150,50,50);
        // 建立一个单选按钮组
        ButtonGroup buttonGroup = new ButtonGroup();
        buttonGroup.add(maleRadio);
        buttonGroup.add(femaleRadio);
        // 复选框组件
        JCheckBox javaCheckBox = new JCheckBox("java");
        javaCheckBox.setBounds(100,200,50,50);
        // 下拉列表组件
        JComboBox cityComboBox = new JComboBox(new String[]{"成都","绵阳","德阳","南充"});
        cityComboBox.setBounds(100,250,250,50);
        // 多选列表组件
        JList likeList = new JList(new String[]{"旅游","篮球","足球","音乐"});
        likeList.setBounds(100,300,250,100);
        // 多行文本框组件
        JTextArea infoTextArea = new JTextArea();

        // 滚动面板容器
        JScrollPane scrollPane = new JScrollPane(infoTextArea);
        scrollPane.setBounds(100,410,250,150);

        // 创建一个子容器
        JPanel panel = new JPanel();
        panel.setLayout(null);
        panel.setBounds(450,50,300,300);
        panel.setBackground(Color.YELLOW);

        JButton button1 = new JButton("ok");
        button1.setBounds(0,0,150,30);
        panel.add(button1);

        // 把组件放到容器中
        this.add(button);
        this.add(label);
        this.add(userTextField);
        this.add(userPasswordField);
        this.add(maleRadio);
        this.add(femaleRadio);
        this.add(javaCheckBox);
        this.add(cityComboBox);
        this.add(likeList);
        this.add(scrollPane);
        this.add(panel);
        // 设置标题栏的图片
        this.setIconImage(iconImg);
        // 设置窗口的关闭策略
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        // 设置标题栏文字
        this.setTitle("我的窗口");
        // 设置窗口的大小
        this.setSize(800,600);
        // 设置窗口默认打开的位置居中
        this.setLocationRelativeTo(null);
        // 设置窗口为显示状态
        this.setVisible(true);
    }

    public static void main(String[] args) {
        new Test01();
    }
}
